@extends('WShop::layout')
@push('styles')
<style type="text/css">
.layui-m-layerchild h3 {margin-top: 0px;}
</style>
@endpush
@section('content')
@component('WShop::public.header')
@slot('page_title'){{$page_title}} @endslot
@slot('btn')
<a href="{{route('f_Wap_Upgrade_apply_record')}}" class="mui-pull-right mui-text-bai" style="margin-top: 12px;font-size: 12px;">历史记录</a>
@endslot
@endcomponent
<div class="mui-content mui-scroll-wrapper" id="pullrefresh">
    <div class="mui-scroll">

        <div class="mui-table-view mui-table-view-chevron mui-bottom mui-jifen-duihuan">
            <div class="mui-dongjie-header mui-text-center">
                <div class="flex">

                    @if($info->level < $sys_level)
                    <div class="flex-item mui-text-center">
                        <span class="mui-text-bai">当前星级</span>
                        <p class="mui-text-bai"> {{get_user_level($info->level)}} </p>
                    </div>
                    <img src="{{asset(config('view.frontend.wap_login').'/images/right.png')}}" style="width: 50px;height: 48px">
                    <div class="flex-item mui-text-center">
                        <span class="mui-text-bai">下一星级</span>
                        <p class="mui-text-bai"> {{get_user_level($next_level)}} </p>
                    </div>
                        @else
                        <div class="flex-item mui-text-center">
                            <span class="mui-text-bai">当前星级</span>
                            <p class="mui-text-bai"> {{get_user_level($info->level)}} </p>
                        </div>
                    @endif
                </div>
            </div>

            <div class="jifen-duihuan-main">
                @if($info->level < $sys_level)
                <div class="jifen-duihuan-list bg-fff">
                    <p class="duihuan_header">升级规则</p>
                    <h4>打款金额</h4>
                    <div >
                        <span class="mui-text-red">{{get_rule('gw_award1')}}</span>
                        <span style="font-size: 12px;">元</span>
                    </div>

                    @if($info->level == 0)
                     <p>激活需要分别向推荐人和 {{get_user_level($sys_level)}}</p>
                     <p>打款{{get_rule('gw_award1')}}元</p>
                        <p>并且要完成{{get_rule('tj_max_deep')}}个激活推荐</p>
                        @else
                        <p>升{{get_user_level($next_level)}}需要您向您的上{{$next_level}}级</p>
                        <p>打款{{get_rule('gw_award1')}}元</p>
                    @endif

                    @if(!$level_count)
                        @if($info->is_active == 0)
                            <a href="javascript:;" id="upgrade_apply" class="mui-btn mui-btn-blue">立即升级</a>
                            @else
                            <a href="javascript:;" disabled class="mui-btn mui-disabled">您已激活完成推荐任务即可升级</a>
                         @endif
                    @else
                        <a href="{{route('f_Wap_Upgrade_apply_match_detail',['id'=>$level_count['id']])}}" class="mui-btn mui-btn-blue">查看信息</a>
                    @endif
                </div>

                @else

                    <div class="jifen-duihuan-list bg-fff">
                        <p class="duihuan_header">升级规则</p>
                        <a href="javascript:;" disabled class="mui-btn mui-disabled">已达到最高星级</a>
                    </div>

            @endif
                    <div class="jifen-duihuan-list bg-fff">
                        <a style="margin-top: 20px;background-color: tomato;" href="{{route('f_Wap_Upgrade_handle_record')}}" class="mui-btn">我的订单</a>
                    </div>
            </div>

        </div>
    </div>
</div>

@include('WShop::public.foot_bar',['active'=>'upgrade'])
@endsection
@push('scripts')
<script>
    var btns = $('#upgrade_apply')
    for(var i=0;i<btns.length;i++){
        btns[i].addEventListener('tap',function(){
            mui.confirm('确定要升级？','提示',function(e){
                if(e.index==1){
                    sendUpgrade();
                }
            })
        })
    }
</script>
<script>
    function sendUpgrade()
    {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            type: 'post',
            url: "{{route('f_Wap_Upgrade_apply')}}",
        }).done(function (response) {
            if(response.status){
                mui.toast(response.msg);
                setTimeout(function () {
                    location.href = response.url;
                }, 2000);
            }else{
                mui.toast(response.msg);
            }
        }).fail(function (XMLHttpRequest) {
            if (XMLHttpRequest.status == 422) {
                var errors = XMLHttpRequest.responseJSON.errors;
                if(typeof errors == 'object') {
                    for (var index in errors) { // 不推荐这样
                        mui.toast(errors[index][0]);
                        break;
                    }
                }else{
                    mui.toast(XMLHttpRequest.responseJSON.msg);

                }
            }else{
                mui.toast('网络异常,请检查连接');
            }

        }).always(function () {

        });
    }
</script>
<script>
    $(function() {
        var is_lock= parseInt("{{$is_lock}}");
        if (is_lock == 1) {
                layer.open({
                    title: [
                        '温馨提示',
                        'background-color:#8DCE16; color:#fff;'
                    ],
                    content: '您还没有设置收款信息，请先去设置。。。',
                    btn: '我知道了',
                    shadeClose: false,
                    yes: function(){
                        window.location.href="{{route('f_Wap_User_index')}}";
                    }
                });
        }
    })
</script>
@endpush